package com.net.xpay.common.validator;

import com.net.xpay.common.domain.partner.PartnerAccount;
import com.net.xpay.common.domain.partner.PartnerAccountDetail;
import com.net.xpay.core.constant.PoseidonErrorCode;
import com.net.common.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author  on 01/04/2018.
 */
@Component
@Slf4j
public class PartnerAccountValidator {

    public void validateAccountEnough(PartnerAccount account, PartnerAccountDetail accountDetail) {
        if (accountDetail == null) {
            return;
        }

        if (accountDetail.getAccountMoney() < 0L) {
            if (account.getMoneyLeft() < 0 || account.getMoneyLeft() + accountDetail.getAccountMoney() < 0L) {
                throw new BusinessException(PoseidonErrorCode.MONEY_NOT_ENOUGH, "余额不足");
            }
        }
    }
}
